﻿//========================================
// All rights reserved (C) 2017-2100
// CLR 版本：	4.0.30319.42000
// 命名空间:	SFJDService.SocketHandle
// 文 件 名：	LanHandle
// 作    者：	WooG
// 联系方式：	wooglle@163.com
// 创建时间：	2017/9/27 14:46:31
//========================================
using Network.UpdateData;
using System;
using System.Net.Sockets;
using System.Threading;

namespace SFJDService.SocketHandle
{
    public class LanHandle
    {
        public LanHandle(Socket socket, byte[] bytes)
        {
            new Thread(() =>
            {
                try
                {
                    Packet packet = new Packet(bytes);
                    //Runtime.Printf("[R]" + packet.ToString());
                    Runtime.Printf(Runtime.TranslatePacket(packet));
                    if (packet.GuidTarget != Guid.Empty && packet.GuidTarget != Runtime.thisUser.UserGuid)
                    {
                        return;
                    }
                    object[] parameters = new object[1];
                    parameters[0] = packet;
                    Type type = Runtime.dictionary[packet.Code];
                    Runtime.Printf("---------------------：" + type.Name);
                    if (socket.Connected)
                        Activator.CreateInstance(type, socket, packet);
                    else
                        Activator.CreateInstance(type, null, packet);
                    //Runtime.Printf("            " + type.Name + "执行完毕！！！");
                }
                catch(System.Collections.Generic.KeyNotFoundException)
                {

                }
                catch
                {
                    throw;
                    //Runtime.Printf(this.GetType().Name + " Erro: " + e.Message );
                }
            }).Start();
        }
    }
}
